<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加客户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">客户代码<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_code" placeholder="请输入被审单位代码(唯一)/18位"
                           lay-verify="required" maxlength="18" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">客户名称<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_audited_object" placeholder="请输入被审单位名称"
                           lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">委托模式<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="radio" name="cus_marital" value="01" lay-filter="entrust" title="自委托" checked>
                    <input type="radio" name="cus_marital" value="02" lay-filter="entrust" title="第三方委托">
                    <input type="radio" name="cus_marital" value="03" lay-filter="entrust" title="合作模式">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">联系电话<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="tel" name="cus_phone" name="cus_phone" lay-verify="required|phone" placeholder="请输入联系人号码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;" id="aa">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">委托方代码<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_entrust_code" maxlength="18" id="cus_entrust_code" lay-verify="required" placeholder="请输入委托方代码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">委托方名称<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_entrust_name" id="cus_entrust_name" lay-verify="required" placeholder="请输入委托方名称"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;" id="hezuo">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">合作方代码<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="tel" name="cus_cooperation_code" maxlength="18" id="cus_cooperation_code" lay-verify="required" placeholder="请输入合作方代码"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">合作方名称<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_cooperation_name" id="cus_cooperation_name" lay-verify="required" placeholder="请输入合作方名称"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">详细地址<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="cus_address" id="cus_address" lay-verify="required" placeholder="请输入被审单位地址！"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容/140个汉字" maxlength="255" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
    layui.use(["form", "okUtils", "form", "layarea", "laydate", "okLayer"], function () {
        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        let laydate = layui.laydate;
        let layarea = layui.layarea;
        okLoading.close();
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(add)", function (data) {
            okUtils.ajax("{% url 'business:customers_insert' %}", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
        $('#aa').hide();
        $('#hezuo').hide();
        let cus_entrust_code = $('#cus_entrust_code').attr('value',"/");
        let cus_entrust_name = $('#cus_entrust_name').attr('value',"/");
        let cus_cooperation_code = $('#cus_cooperation_code').attr('value',"/");
        let cus_cooperation_name = $('#cus_cooperation_name').attr('value',"/");
        form.on("radio(entrust)", function (data) {
            let value = data.value;
            if (value === '01') {
                $('#aa').hide();
                $('#hezuo').hide();

            } else if (value === '02') {
                $('#aa').show();
                let cus_entrust_code = $('#cus_entrust_code').attr('value',"");
                let cus_entrust_name = $('#cus_entrust_name').attr('value',"");
                $('#hezuo').hide();
            } else {
                $('#aa').hide();
                $('#hezuo').show();
                let cus_cooperation_code = $('#cus_cooperation_code').attr('value', "");
                let cus_cooperation_name = $('#cus_cooperation_name').attr('value', "");
            }
        })
    });
</script>
</body>
</html>
